home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- #
- # Laptop mode tools module: switch config files based on power state.
- #
-
- if [ x$CONTROL_CONFIG_FILES = x1 ] ; then
- echo "Swapping out configuration files." >> $OUTPUT
- for CONFFILE in $CONFIG_FILES ; do
- if [ -e $CONFFILE ] ; then
- #
- # Initialize the -nolm-ac, -lm-ac and -batt files if they don't
- # already exist.
- #
- if [ ! -e "$CONFFILE-nolm-ac" ] ; then
- cp $CONFFILE $CONFFILE-nolm-ac
- fi
- if [ ! -e "$CONFFILE-lm-ac" ] ; then
- cp $CONFFILE $CONFFILE-lm-ac
- fi
- if [ ! -e "$CONFFILE-batt" ] ; then
- cp $CONFFILE $CONFFILE-batt
- fi
-
- #
- # Create the .lmbackup file
- #
- if [ "`readlink -f $CONFFILE`" != "$CONFFILE" ] ; then
- echo "$CONFFILE is a symlink." >> $OUTPUT
- if [ ! -f "$CONFFILE.lmbackup" ] ; then
- echo "But there is no $CONFFILE.lmbackup." >> $OUTPUT
- echo "Creating it now from $CONFFILE-nolm-ac." >> $OUTPUT
- cp "$CONFFILE-nolm-ac" "$CONFFILE.lmbackup"
- fi
- else
- echo "$CONFFILE is not a symlink." >> $OUTPUT
- if [ "$STATE" = "enabled" ] ; then
- echo "Saving it to $CONFFILE.lmbackup." >> $OUTPUT
- cp --backup=numbered "$CONFFILE" "$CONFFILE.lmbackup"
- fi
- fi
-
- #
- # Swizzle the config file
- #
- if [ "$STATE" != "enabled" ] ; then
- echo "Laptop mode is not enabled. Restoring $CONFFILE." >> $OUTPUT
- if [ -f "$CONFFILE.lmbackup" ] ; then
- mv "$CONFFILE.lmbackup" "$CONFFILE"
- elif [ "`readlink -f $CONFFILE`" != "$CONFFILE" ] ; then
- echo "ERROR: $CONFFILE is a symlink but $CONFFILE.lmbackup is not present."
- fi
- elif [ $ON_AC -eq 1 ] ; then
- if [ "$ACTIVATE" -eq 1 ] ; then
- echo "Pointing config file $CONFFILE to $CONFFILE-lm-ac." >> $OUTPUT
- ln -fs "$CONFFILE-lm-ac" "$CONFFILE"
- else
- echo "Pointing config file $CONFFILE to $CONFFILE-nolm-ac." >> $OUTPUT
- ln -fs "$CONFFILE-nolm-ac" "$CONFFILE"
- fi
- else
- echo "Pointing config file $CONFFILE to $CONFFILE-batt." >> $OUTPUT
- ln -fs "$CONFFILE-batt" "$CONFFILE"
- fi
- fi
- done
- # Notify daemons of configuration change.
- for PROGRAM in $CONFIG_FILE_SIGNAL_PROGRAMS ; do
- $LM_VERBOSE && echo "Sending SIGHUP to all $PROGRAM processes." >> $OUTPUT
- killall -q -HUP $PROGRAM
- done
-
-
- if [ ! -z "$CONFIG_FILE_RELOAD_SERVICES" ] ; then
- # Determine how we can start/restart services.
- if ( which invoke-rc.d > /dev/null ) ; then
- # Debian uses invoke-rc.d
- RCPROG="invoke-rc.d "
- INITSCRIPT=laptop-mode
- elif ( which service > /dev/null ) ; then
- # RedHat uses service
- RCPROG="service "
- INITSCRIPT=laptop-mode
- else
- # Any other -- we start the init script it ourselves.
-
- # Try non-link directories first, then try links. This helps if one of
- # the locations is linked to another, which is the case on some distros.
- if [ -d /etc/rc.d/init.d -a ! -L /etc/rc.d/init.d ] ; then
- INIT_D=/etc/rc.d/init.d
- elif [ -d /etc/rc.d -a ! -L /etc/rc.d -a ! -d /etc/rc.d/init.d ] ; then
- INIT_D=/etc/rc.d
- elif [ -d /etc/init.d -a ! -L /etc/init.d ] ; then
- INIT_D=/etc/init.d
- elif [ -d /etc/rc.d/init.d ] ; then
- INIT_D=/etc/rc.d/init.d
- elif [ -d /etc/rc.d ] ; then
- INIT_D=/etc/rc.d
- elif [ -d /etc/init.d ] ; then
- INIT_D=/etc/init.d
- else
- $LM_VERBOSE && echo "Cannot determine location of init scripts." >> $OUTPUT
- exit 1
- fi
-
- RCPROG="$INIT_D/"
- fi
-
- for SERVICE in $CONFIG_FILE_RELOAD_SERVICES ; do
- $LM_VERBOSE && echo "Reloading service $SERVICE." >> $OUTPUT
- $RCPROG$SERVICE reload
- done
- fi
- fi
-